<%@ page language="java" pageEncoding="UTF-8"%>

<script type="text/javascript">
var detailValidator;

var editAction = "${param.action}";

function selectIndicator() {
	$.openDialog("#dialog",
			{height:350,
			width:300,
			minHeight:350,
			minWidth:300,
			loadPage:ctx+"/biz/indicator/query.jsp",
			title:"选择指标项"},
			function(data) {
				$("#indicator").data("id",data.data("id"));
				$("#indicator").val(data.data("name"));
			});
}

function saveDetail() {
	if (!detailValidator.form()) {
		return;
	}
	doSaveDetail();
}

function doSaveDetail() {
	var data = {
			id : $("#indicatorValueId").val(),
			name : $("#indicatorValueName").val(),
			indicatorId : $("#indicator").data("id"),
// 			webAccessAllowed:$(":radio[name=userWebAccessAllowed]:checked").val(),
			description : $("#description").val()
		};
	
	block("#detailForm");
	$.ajax({
		type: "POST",
		url: "save.json",
		data: data,
		dataType: "json",
		success: saveSucceedCallback,
		error:function(message){
			unblock("#detailForm");
			$.alert(message);
		}
	});
}

function saveSucceedCallback(data) {
	unblock("#detailForm");
	if (!data.succeed) {
		$.notice(data.message);
		return;
	}

	$("#indicatorValueId").val(data.data.id);
	if (editAction = "new") {
		window.location.href = "edit.do?id="+data.data.id;
		$.info("保存成功！");
	}
	else {
		$.notice("保存成功！");
	}
}

$(document).ready(function() {
	$("#tabs").tab("show");
	$("#indicator").data("id",$("#indicatorId").val());
	
	var id = $("#indicatorValueId").val();
	if(id != ""){
		$("#creatorCg").show();
		$("#createDateTimeCg").show();
	}

	detailValidator = $("#detailForm").validate({
		rules: {
			indicatorValueName:{required:true, maxlength:50},
			indicator:{required:true},
			description:{maxlength:255}
		},
		messages:{
			indicatorValueName:{required:"请输入用户名"},
			indicator:{required:"请选择所属指标项"}
		}
	});
	$().maxlength();

});

</script>

<form id="detailForm" class="form-horizontal">
<input type="hidden" id="indicatorValueId" value="${data.id}">
<input type="hidden" id="indicatorId" value="${data.indicatorId}">
	<fieldset>
	<div class="control-group">
		<label for="indicatorValueName"  class="control-label">名称：</label>
		<div class="controls">
		<input type="text" id="indicatorValueName" name="indicatorValueName" class="required" maxlength="50" value="${data.name}"> <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="userExecOrgan" class="control-label">所属指标项：</label>
		<div class="controls">
		<input type="text" id="indicator" readonly="readonly" name="indicator" value="${data.indicatorName}">
		<input type="button" class="btn" value="选择" onclick="selectIndicator()"> <span class="cms_color_required">*</span>
		</div>
	</div>
<!-- 	<div class="control-group"> -->
<!-- 		<label for="userMobileAccessAllowed" class="control-label">手机访问权限：</label> -->
<!-- 		<div class="controls"> -->
<%-- 		<input type="radio" name="userMobileAccessAllowed" value="true" ${data.mobileAccessAllowed?'checked=checked':''}>允许 --%>
<%-- 		<input type="radio" name="userMobileAccessAllowed" value="false" ${data.mobileAccessAllowed?'':'checked=checked'}>不允许 --%>
<!-- 		</div> -->
<!-- 	</div> -->
	<div class="control-group">
		<label for="description" class="control-label">描述：</label>
		<div class="controls">
		<textarea id="description" name="description" maxlength="255">${data.description}</textarea>
		</div>
	</div>
	
	<div class="control-group" style="display: none;" id="creatorCg">
		<label for="creator"  class="control-label">创建人：</label>
		<div class="controls">
		<input type="text" id="creator" name="creator" readonly="readonly" value='${data.creatorName}'/>
		</div>
	</div>
	<div class="control-group" style="display: none;" id="createDateTimeCg">
		<label for="createDateTime"  class="control-label">创建时间：</label>
		<div class="controls">
		<input type="text" id="createDateTime" name="createDateTime" readonly="readonly" value='${data.createDateTime}'/>
		</div>
	</div>
	
	<div class="form-actions">
		<a href="#" class="btn btn-primary" onclick="saveDetail()"><i class="icon-ok"></i>保存</a>
	</div>
	</fieldset>
</form>
